<?php
/**
 *   File functions:
 *   Show text in chat
 *
 *   @name                 : chatmsg.php                            
 *   @copyright            : (C) 2004,2005,2006 Vallheru Team based on Gamers-Fusion ver 2.5
 *   @author               : thindil <thindil@users.sourceforge.net>
 *   @version              : 1.0
 *   @since                : 03.02.2006
 *
 */

//
//
//       This program is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation; either version 2 of the License, or
//   (at your option) any later version.
//
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//
//   You should have received a copy of the GNU General Public License
//   along with this program; if not, write to the Free Software
//   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// $Id$
require_once('includes/config.php');
require_once('includes/sessions.php');
require_once('libs/Smarty.class.php');

$smarty = new Smarty;
$smarty -> compile_check = true;

$stat = $db -> Execute("SELECT id, page, rank, style, graphic FROM players WHERE email='".$_SESSION['email']."'");
/**
* Get the localization for game
*/
require_once("languages/pl/chatmsg.php");

/**
* Select style for chat
*/
if ($stat -> fields['graphic']) 
{
    $smarty -> template_dir = "./templates/".$player -> graphic;
    $smarty -> compile_dir = "./templates_c/".$player -> graphic;
    $strCss = '';
}   
    else
{
    $smarty -> template_dir = './templates';
    $smarty -> compile_dir = './templates_c';
    $strCss = $stat -> fields['style'];
}


$chat = $db -> SelectLimit("SELECT * FROM priv WHERE ownerid=".$stat -> fields['id']." OR senderid=".$stat -> fields['id']." ORDER BY id DESC", 10);
$e = $chat -> RecordCount();


$arrtext = array();
$arrauthor = array();
$arrsenderid = array();
$i = $e-1;
    $smarty -> assign ("Showid", 1);
while (!$chat -> EOF) 
{
    $text = wordwrap($chat -> fields['chat'],50,"\n",1);
    $arrtext[$i] = $text;
    $arrauthor[$i] = $chat -> fields['user'];
	if ($chat -> fields['ownerid'] != $stat -> fields['id']) 
	{
	$arrsenderid[$i] = "do <a href=priv.php?view=&to=".$chat -> fields['ownerid']." target=\"_parent\">".$chat -> fields['ownerid']."</a>";
	} else {
	$arrsenderid[$i] = "od <a href=priv.php?view=&to=".$chat -> fields['senderid']." target=\"_parent\">".$chat -> fields['senderid']."</a>";
	}	
    $chat -> MoveNext();
    $i = $i - 1;
}
$chat -> Close();



$query = $db -> Execute("SELECT id FROM priv where ownerid=".$stat -> fields['id']." OR senderid=".$stat -> fields['id']);
$numchat = $query -> RecordCount();
$query -> Close();

if ($stat -> fields['page'] != 'Rozmowa') $db -> Execute("UPDATE players SET page='Rozmowa' WHERE id=".$stat -> fields['id']);

$smarty -> assign ( array("Author" => $arrauthor, 
    "Text" => $arrtext, 
    "Senderid" => $arrsenderid,
    "Charset" => CHARSET,
    "Thereis" => THERE_IS,
    "Texts" => TEXTS,
    "Cplayers" => C_PLAYERS,
    "Cid" => " do",
    "CSS" => $strCss));
$smarty -> display ('privmsgs.tpl');

?>
